package test

import (
	"awesome/model"
	"fmt"
)

func init() {
	fmt.Println("=============init=============")
}
func getAllPerson() (all []*model.Person) {
	all = append(all, &model.Person{
		Name:  "张三",
		Age:   18,
		Level: 1,
	})
	all = append(all, &model.Person{
		Name:  "李四",
		Age:   18,
		Level: 1,
	})
	return
}

func ChangeOne(m *model.Person) {
	m.Level = 2
}
func TestChangeOne() {
	var aa = model.Person{
		Name:  "张三",
		Age:   18,
		Level: 1,
	}
	ChangeOne(&aa)
	fmt.Println(aa.Level)
}

// 还有go中，原则上 slice 不用指针的
func ChangeLevel(all *[]model.Person) {
	for _, person := range *all {
		person.Level = 2
	}
}
func TestChangeLevel() {
	var arr []model.Person
	arr = append(arr, model.Person{
		Name:  "张三",
		Age:   18,
		Level: 1,
	})
	arr = append(arr, model.Person{
		Name:  "李四",
		Age:   18,
		Level: 1,
	})
	ChangeLevel(&arr)
	fmt.Println(arr[0].Level)
}

func main() {
	//TestChangeLevel()

}
